package com.lmt.service.impl;

import com.lmt.base.ResultData;
import com.lmt.entity.TagTemp;
import com.lmt.repository.TagTempRepository;
import com.lmt.service.TagTempService;
import com.lmt.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Date 2018/07/17
 *
 * @author MT-Lin
 */
@Service("TagTempServiceImpl")
public class TagTempServiceImpl implements TagTempService {

	private final TagTempRepository tagTempRepository;

	@Autowired
	public TagTempServiceImpl(TagTempRepository tagTempRepository) {
		this.tagTempRepository = tagTempRepository;
	}

	@Override
	public ResultData save(TagTemp tagTemp) {
		TagTemp exist = this.tagTempRepository.findByResourceTempId(tagTemp.getId());
		if (null != exist) {
			return ResultUtil.newFail("该资源已有标签存在");
		}
		this.tagTempRepository.save(tagTemp);
		if (null == tagTemp.getId()) {
			return ResultUtil.newFail("待审核资源标签保存失败");
		}
		return ResultUtil.newSuccess("待审核资源标签保存成功");
	}
}
